package com.ruoyi.manager.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manager.domain.ArvinDatabase;
import com.ruoyi.manager.service.IArvinDatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据库账号管理Controller
 * 
 * @author ruoyi
 * @date 2021-08-28
 */
@RestController
@RequestMapping("/database/database")
public class ArvinDatabaseController extends BaseController
{
    @Autowired
    private IArvinDatabaseService arvinDatabaseService;

    /**
     * 查询数据库账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('database:database:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArvinDatabase arvinDatabase)
    {
        startPage();
        List<ArvinDatabase> list = arvinDatabaseService.selectArvinDatabaseList(arvinDatabase);
        return getDataTable(list);
    }

    /**
     * 导出数据库账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('database:database:export')")
    @Log(title = "数据库账号管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ArvinDatabase arvinDatabase)
    {
        List<ArvinDatabase> list = arvinDatabaseService.selectArvinDatabaseList(arvinDatabase);
        ExcelUtil<ArvinDatabase> util = new ExcelUtil<ArvinDatabase>(ArvinDatabase.class);
        return util.exportExcel(list, "database");
    }

    /**
     * 获取数据库账号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('database:database:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(arvinDatabaseService.selectArvinDatabaseById(id));
    }

    /**
     * 新增数据库账号管理
     */
    @PreAuthorize("@ss.hasPermi('database:database:add')")
    @Log(title = "数据库账号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArvinDatabase arvinDatabase)
    {
        arvinDatabase.setUserId(getUserId());
        return toAjax(arvinDatabaseService.insertArvinDatabase(arvinDatabase));
    }

    /**
     * 修改数据库账号管理
     */
    @PreAuthorize("@ss.hasPermi('database:database:edit')")
    @Log(title = "数据库账号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArvinDatabase arvinDatabase)
    {
        return toAjax(arvinDatabaseService.updateArvinDatabase(arvinDatabase));
    }

    /**
     * 删除数据库账号管理
     */
    @PreAuthorize("@ss.hasPermi('database:database:remove')")
    @Log(title = "数据库账号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arvinDatabaseService.deleteArvinDatabaseByIds(ids));
    }
}
